//
//  BaseLogic.m
//  MyApplication
//
//  Created by issac on 15/7/29.
//  Copyright (c) 2015年 52xiaoluo. All rights reserved.
//

#import "BaseLogic.h"
#import "SecrityLogic.h"
#import "NetEngine.h"
//#import "MainCmd.pb.h"



static UInt32 seq  = 0;
void initSeq() {
    seq = arc4random();
}

@implementation BaseLogic
-(void)sendRequest:(NSString *)cmd PBMsg:(PBGeneratedMessage *)msg {
    PacketBuilder *pb = [[PacketBuilder alloc] init];
    
    [pb setCmd:cmd];
    [pb setSeq:seq];
    seq++;
    [pb setUin: [[UserLogic shareInstance] getUserId] ];
    [pb setImei:[[[UIDevice currentDevice] identifierForVendor] UUIDString]];
    [pb setAppName:@"com.xl.rentkeeper"];
    [pb setAppVer:BundleVersion];
    [pb setPlatform:AppPlatformIos];
    
    NSData *encrpt;
    if ([cmd isEqualToString:CMD_USER_LOGIN]) {
        encrpt =[[SecrityLogic shareInstance] encryptDefault:msg.data];
    } else {
        encrpt =[[SecrityLogic shareInstance] encryptSession:msg.data];
    }
    [pb setEBody:encrpt];    
    
    Request *request = [[Request alloc]init];
    request.delegate = self;
    request.packet = [pb build];
    request.oriPb = msg;
    [[NetEngine shareInstance] sendRequest:request];
}

- (void)onResult:(Packet *)result req:(Request *)req
{
    
}
@end
